package com.nmmhu.bean;
import com.nmmhu.annotation.MyAnnotation;
import java.lang.reflect.Method;

/**
 * @author nmm
 * @date 2024-04-2024/4/2
 * @deriction njm......
 */
public class Calc {

    @MyAnnotation("1000")
    public static void CalcSum(int myNum) throws Exception{
        Class<Calc> calcClass = Calc.class;
        Method calcSum = calcClass.getDeclaredMethod("CalcSum", int.class);//获取求和方法
        int sumNum=Integer.valueOf(calcSum.getAnnotation(MyAnnotation.class).value());//获取方法上设置的注解（求和上限）

        if (myNum<=sumNum) {
            System.out.println(myNum);
            int sum=0;
            for (int i =1; i <=myNum; i++) {
                sum+=i;
            }
            System.out.println(String.format("1到%s的和为%s",myNum,sum));
        }else {
            throw  new RuntimeException("输入的求和数值超过上限"+sumNum);
        }
    }

}